package io.gitee.dqcer.mcdull.uac.provider.web.car.service.impl;

import java.util.ArrayList;
import java.util.List;

import io.gitee.dqcer.mcdull.uac.provider.system.mapper.CarVehicleMapper;
import io.gitee.dqcer.mcdull.uac.provider.web.car.domain.CarVehicleRepairVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.gitee.dqcer.mcdull.uac.provider.web.car.mapper.CarVehicleRepairMapper;
import io.gitee.dqcer.mcdull.uac.provider.web.car.domain.CarVehicleRepair;
import io.gitee.dqcer.mcdull.uac.provider.web.car.service.ICarVehicleRepairService;

import javax.annotation.Resource;

/**
 * 维修监控Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-10
 */
@Service
public class CarVehicleRepairServiceImpl implements ICarVehicleRepairService 
{
    @Autowired
    private CarVehicleRepairMapper carVehicleRepairMapper;

    @Resource
    private CarVehicleMapper carVehicleMapper;

    /**
     * 查询维修监控
     * 
     * @param repairId 维修监控主键
     * @return 维修监控
     */
    @Override
    public CarVehicleRepair selectCarVehicleRepairByRepairId(Long repairId)
    {
        return carVehicleRepairMapper.selectCarVehicleRepairByRepairId(repairId);
    }

    /**
     * 查询维修监控列表
     * 
     * @param carVehicleRepair 维修监控
     * @return 维修监控
     */
    @Override
    public List<CarVehicleRepairVO> selectCarVehicleRepairList(CarVehicleRepair carVehicleRepair)
    {
        List<CarVehicleRepairVO> list = new ArrayList<>();
        List<CarVehicleRepair> carVehicleRepairs = carVehicleRepairMapper.selectCarVehicleRepairList(carVehicleRepair);
        for (CarVehicleRepair repair : carVehicleRepairs) {
            CarVehicleRepairVO vo = this.convertVO(repair);
            vo.setCarNo(carVehicleMapper.
                    selectCarVehicleByVehicleId(vo.getVehicleId()).getLicensePlate());
            list.add(vo);
        }
        return list;
    }

    private CarVehicleRepairVO convertVO(CarVehicleRepair repair) {
        CarVehicleRepairVO carVehicleRepairVO = new CarVehicleRepairVO();
        carVehicleRepairVO.setRepairId(repair.getRepairId());
        carVehicleRepairVO.setVehicleId(repair.getVehicleId());
        carVehicleRepairVO.setRepairType(repair.getRepairType());
        carVehicleRepairVO.setRepairDescription(repair.getRepairDescription());
        carVehicleRepairVO.setRepairCost(repair.getRepairCost());
        carVehicleRepairVO.setRepairTime(repair.getRepairTime());
        carVehicleRepairVO.setEstimatedCompletionTime(repair.getEstimatedCompletionTime());
        carVehicleRepairVO.setActualCompletionTime(repair.getActualCompletionTime());
        carVehicleRepairVO.setRepairStatus(repair.getRepairStatus());
        carVehicleRepairVO.setResponsiblePerson(repair.getResponsiblePerson());
        carVehicleRepairVO.setSceneImage(repair.getSceneImage());
        carVehicleRepairVO.setCreatedAt(repair.getCreatedAt());
        carVehicleRepairVO.setUpdatedAt(repair.getUpdatedAt());
        carVehicleRepairVO.setSearchValue(repair.getSearchValue());
        carVehicleRepairVO.setCreateBy(repair.getCreateBy());
        carVehicleRepairVO.setCreateTime(repair.getCreateTime());
        carVehicleRepairVO.setUpdateBy(repair.getUpdateBy());
        carVehicleRepairVO.setUpdateTime(repair.getUpdateTime());
        carVehicleRepairVO.setRemark(repair.getRemark());
        carVehicleRepairVO.setParams(repair.getParams());
        return carVehicleRepairVO;
    }

    /**
     * 新增维修监控
     * 
     * @param carVehicleRepair 维修监控
     * @return 结果
     */
    @Override
    public int insertCarVehicleRepair(CarVehicleRepair carVehicleRepair)
    {
        return carVehicleRepairMapper.insertCarVehicleRepair(carVehicleRepair);
    }

    /**
     * 修改维修监控
     * 
     * @param carVehicleRepair 维修监控
     * @return 结果
     */
    @Override
    public int updateCarVehicleRepair(CarVehicleRepair carVehicleRepair)
    {
        return carVehicleRepairMapper.updateCarVehicleRepair(carVehicleRepair);
    }

    /**
     * 批量删除维修监控
     * 
     * @param repairIds 需要删除的维修监控主键
     * @return 结果
     */
    @Override
    public int deleteCarVehicleRepairByRepairIds(Long[] repairIds)
    {
        return carVehicleRepairMapper.deleteCarVehicleRepairByRepairIds(repairIds);
    }

    /**
     * 删除维修监控信息
     * 
     * @param repairId 维修监控主键
     * @return 结果
     */
    @Override
    public int deleteCarVehicleRepairByRepairId(Long repairId)
    {
        return carVehicleRepairMapper.deleteCarVehicleRepairByRepairId(repairId);
    }
}
